<script type="text/javascript">
    common.setMainTitle("Quản trị product " +"<div>&nbsp;</div>");
</script>

<form id="mainform" name="fr" method="POST" action="/admin/product/input">
    <div id="toolbar-button">
        <div class="item" onclick="add()" id="addButton" title="Add">
            <div id="addnew-global-button"></div>
        </div>
    </div>
    
    <table style="margin-top: 10px; clear: both;" border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
        <thead>
            <tr>
                <th width="3%" class="table-header-repeat line-left" style="text-align: center">
                    <input type="checkbox" name="DELALL" onclick="selectAll(this,'ITEM')"/>
                </th>
                <th class="table-header-repeat line-left" style="text-align: left"><a>Image</a></th>
                <th class="table-header-repeat line-left" style="text-align: left"><a>Name</a></th>
                <th class="table-header-repeat line-left" style="text-align: left"><a>Description</a></th>
                <th class="table-header-repeat line-left" style="text-align: left"><a>Category</a></th>
                <th class="table-header-repeat line-left" style="text-align: left"><a>Price</a></th>
                <th class="table-header-repeat line-left" style="text-align: left"><a>Action</a></th>
            </tr>
        </thead>
        
        <tbody>
            <script type="text/javascript">
                var arrNav = new Array();
            </script>
            <?php
                if(count($this->data) == 0){
                    echo "<tr><td colspan='12'> There is not any data</td></tr>";
                }else{
                    $stt = 1;
                    foreach($this->data as $item){
                        ?>
                        <tr style="cursor: pointer">
                            <td style="text-align: center; padding-left: 0px;">
                                <input type="checkbox" name="ITEM[]" value="<?= $item['PRODUCTID']?>"/>
                            </td>
                            <td>
                                <?php
                                if($item['IMAGEURL'] != ""){
                                    ?>
                                    <img width="50" height="50" src="<?=$item['IMAGEURL']?>"/>
                                    <?php
                                }
                                ?>
                            </td>
                            <td> <?=$item['NAME'];?></td>
                            <td> <?=$item['DESCRIPTION'];?></td>
                            <td> <?=$item['CATEGORYNAME'];?></td>
                            <td> <?=$item['PRICE'];?></td>
                            
                            <td style="text-align: center">
                                <select id="<?php echo 'actionbox'.$item['PRODUCTID']?>" name="actionbox" onchange="chooseAction(<?=$item['PRODUCTID'] ?>)">
                                    <option value="0">Choosen an Actions</option>
                                    <option value="<?=$item['PRODUCTID']?>">Edit</option>
                                    <option value="<?=$item['PRODUCTID']?>">Delete</option>
                                </select>  
                            </td>
                        </tr>
                        <?php
                        $stt++;
                    }
                }
            ?>
        </tbody>
    </table>
</form>
<script type="text/javascript">
    function chooseAction(productId){
        text = $("#actionbox"+productId+" option:selected").text();
        if(text == "Edit"){
            window.location = "/admin/product/input/id/"+productId+"/limit/"+"<?= $this->limit?>/page/"+"<?=$this->page?>";
        }else if(text == "Delete"){
            check = confirm("Do you want to delete this product?");
            if(check){
                window.location = "/admin/product/delete/id/"+productId+"/limit/"+"<?= $this->limit?>/page/"+"<?=$this->page?>";
            }
        }
    }
    
    function add(){
        window.location = "/admin/product/input";
    }
</script>